clear
rng(23)

params = [0.1207	0.0296	0.1584	1.538	7.108	0.938];
transition_year = 300;
transition_pre_period = 50;
transition_post_period = 149;
max_year = 460;
import_tariff_entry = 4;
import_tariff_counterfactual = 1.5;
beta = 0.95;
sims = 10;
num_comps = 10;
num_moments = 8;
parpool('local',num_comps)

%%% SIMULATE THE ECONOMY ANS TRACK THE TIME-SERIES OF MOMENTS AFTER A SHOCK
%%% TO TRADE COSTS
outputs_sims = zeros(transition_pre_period+transition_post_period+1,num_moments);
repeats = 0
while repeats <= sims
parfor computer_num = 1:num_comps
[outputs] = steady_state_simulation_IRF(params, max_year, transition_year, transition_pre_period, transition_post_period, import_tariff_entry, import_tariff_counterfactual);
outputs_sims = outputs_sims+outputs;
end
repeats = repeats+1
end
outputs_avg = outputs_sims/(sims*(repeats));

save('IRF_trade_cost.mat','outputs_avg');
%save('IRF_trade_cost_symmetric.mat','outputs_avg');

%load('IRF_trade_cost_symmetric.mat');
load('IRF_trade_cost.mat');

% output = [omega_tograph' relative_product_wage_tograph' USgrowth_tograph OECDgrowth_tograph USexportshare_tograph' OECDexportshare_tograph' UStradeelasticity_tograph OECDtradeelasticity_tograph];                       
omega_vec = outputs_avg(:,1);
relative_product_wage_vec = outputs_avg(:,2);
US_growth_vec = outputs_avg(:,3);
OECD_growth_vec = outputs_avg(:,4);
US_export_share_vec = outputs_avg(:,5);
OECD_export_share_vec = outputs_avg(:,6);
US_trade_elasticity_vec = outputs_avg(:,7);
OECD_trade_elasticity_vec = outputs_avg(:,8);

% hold on
% plot(-50:149,omega_vec,'k')
% set(gcf,'color','white')
% set(gca,'linewidth', 1.2)
% ylim([0.9 1.5])
% yticks([0.9 1 1.1 1.2 1.3 1.4 1.5])
% xlabel('Year')
% hold off
% 
% hold on
% plot(-50:149,relative_product_wage_vec,'k')
% set(gcf,'color','white')
% set(gca,'linewidth', 1.2)
% %ylim([0.9 1.5])
% %yticks([0.9 1 1.1 1.2 1.3 1.4 1.5])
% xlabel('Year')
% hold off
% 
% hold on
% plot(-50:149,(US_growth_vec-1)*100,'k')
% plot(-50:149,(OECD_growth_vec-1)*100,'k--')
% set(gcf,'color','white')
% set(gca,'linewidth', 1.2)
% ylim([1.5 7])
% %yticks([1.5 2 2.5 3 3.5 4 4.5 5])
% legend('Domestic', 'Foreign')
% legend boxoff
% xlabel('Year')
% hold off

%%% TRADE SHARE GRAPH IN THE LEFT PANEL OF FIGURE 5
hold on
plot(-50:149,US_export_share_vec,'k','linewidth', 2.0)
set(gcf,'color','white')
set(gca,'linewidth', 1.6)
ax = gca;
ax.YAxis.FontWeight = 'bold';
ax.XAxis.FontWeight = 'bold';
ax.YAxis.FontSize = 16
ax.XAxis.FontSize = 16
hold off

%%% TRADE ELASTICITY GRAPH IN THE RIGHT PANEL OF FIGURE 5
hold on
plot(-50:149,-US_trade_elasticity_vec,'k','linewidth', 2.0)
%plot(-50:149,-OECDtradeelasticity_vec,'k--')
set(gcf,'color','white')
set(gca,'linewidth', 1.6)
ax = gca;
ax.YAxis.FontWeight = 'bold';
ax.XAxis.FontWeight = 'bold';
ax.YAxis.FontSize = 16
ax.XAxis.FontSize = 16
hold off



